<template>
    <div class="dataDownload app-container">
      <div class="__page">
        <div class="search_box">
          <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="标的名称:">
              <el-input prefix-icon="el-icon-search" v-model="formInline.lotsName" placeholder="请输入标的名称" size="mini"></el-input>
            </el-form-item>
            <el-form-item label="处置单位:">
              <el-input prefix-icon="el-icon-search" v-model="formInline.disposalUnit" placeholder="请输入处置单位" size="mini"></el-input>
            </el-form-item>
            <el-form-item>
              
            </el-form-item>
          </el-form>
          <div>
            <el-button type="primary" @click="searching" size="mini">检索</el-button>
            <el-button size="mini">重置</el-button>
          </div>
        </div>
        <div class="table_box">
          <el-table
            :data="tableData"
            border
            stripe
            height="670"
            style="width: 100%"
            :header-cell-style="{background:'#f5f7fa'}">
            <el-table-column label="标的名称" prop="name" align="center">
            </el-table-column>
            <el-table-column label="处置地点" prop="site" align="center">
            </el-table-column>
            <el-table-column label="处置单位" prop="dispose_unit" align="center">
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button type="primary" @click="goDetailsDown(scope.row)" size="mini">资料下载</el-button>
              </template>
            </el-table-column>
          </el-table>

          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page"
            :page-sizes="[7, 20, 30, 40]"
            :page-size="limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div>
      
    </div>
  </template>
  
  <script>
  import { mapGetters,mapState} from 'vuex'
  import {listDataDownload} from '@/api/release'
  export default {
    name: 'dataDownload',
    data(){
      return{
        formInline:{
          disposalUnit:'',
          lotsName:''
        },
        page:1,
        limit:10,
        total:0,
        tableData:[],
      }
    },
    created(){

      this.list();
    },
    computed:{
        ...mapGetters(['tagList']),
        ...mapState('user', ['userInfo'])
    },
    methods:{
      list(){
        let i = this.userInfo.company_id;
        listDataDownload({company_id:i}).then(res =>{
          this.tableData = res.data;
        })
      },
      //点击检索
      searching(){

      },
      goDetailsDown(row){
        let routeObj = {name:'资料下载',url:`/information/DownStatistic?lotId=${row.id}`,title:'DownStatistic',component:'DownStatistic'};  
        var only = this.contains(routeObj.title);
        if(!only){//说明arr中不存在id为objid的对象
          this.$store.dispatch('user/ADD_TAGS',routeObj);
          this.$router.push(`/information/DownStatistic?lotId=${row.id}`)
        }else{
          this.$router.push(`/information/DownStatistic?lotId=${row.id}`);
        }
      },
      contains(title) {
        for (var i = 0; i < this.tagList.length; i++) {
          if (this.tagList[i].title === title) {
            return true;
          }
        }
        return false;
      },
      // 分页
      handleSizeChange(val) {
        this.limit = val
        this.list()
      },
      // 分页
      handleCurrentChange(val) {
        this.page = val
        this.list()
      },
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .dataDownload {
    .search_box{
      display: flex;
      align-content: center;
      justify-content: space-between;
    }
    
  }
  </style>
  